<?php

/**
 * This class manages all database queries (or other operations)
 * concerning Status_flag.
 */
class Model_Statusflag extends Model_Base
{

    /**
     * Database table name
     *
     * @var string
     */
    private $name = 'status_flag';

    /**
     * Lists all status_flags.
     * 
     * @return array an array of (associative) arrays
     */
    public function listAll()
    {
	$select = $this->db->select()
		->from($this->name);
	return $this->db->fetchAll($select);
    }

    /**
     * Updates status_flags data.
     * 
     * @param array $status_flag the status_flags data
     */
    public function update(array $status_flag)
    {
	$where = $this->db->quoteInto('id = ?', $status_flag['id']);
	$this->db->update($this->name, $status_flag, $where);
    }

    /**
     * Get status_flags data. The status_flag is identified by its id.
     * 
     * @param type $status_flag the status_flags id
     * @return array the status_flags data, or FALSE if not found
     */
    public function find($id)
    {
	$select = $this->db->select()
		->from($this->name)
		->where('id = ?', $id);
	return $this->db->fetchRow($select);
    }

    /**
     * 
     * @return \Zend_Date
     */
    public function getDailyCaretimeFrom()
    {
	$statusFlags = $this->listAll()[0];
	return new Zend_Date($statusFlags['daily_caretime_from'], Zend_Date::TIME_MEDIUM);
    }

    /**
     * 
     * @return \Zend_Date
     */
    public function getDailyCaretimeTo()
    {
	$statusFlags = $this->listAll()[0];
	return new Zend_Date($statusFlags['daily_caretime_to'], Zend_Date::TIME_MEDIUM);
    }

    /**
     * 
     * @param Zend_Date $date
     * @return boolean
     */
    public function inCaretime(Zend_Date $date)
    {
	$hourOfDate = $date->getTime();
	$inCaretime = $hourOfDate->compare($this->getDailyCaretimeFrom()->getTimestamp(), Zend_Date::TIMESTAMP) != -1 &&
		$hourOfDate->compare($this->getDailyCaretimeTo()->getTimestamp(), Zend_Date::TIMESTAMP) != 1;
	return $inCaretime;
    }

    public function getMaxParallelCareSitsTotal()
    {
	$statusFlags = $this->listAll()[0];
	return $statusFlags['max_caresits'];
    }

    public function getMaxParallelCareSitsForChildrenUnderOne()
    {
	$statusFlags = $this->listAll()[0];
	return $statusFlags['max_children_under_age_1'];
    }

    public function getMaxWeeklyCareSitsForChildrenUnderOne()
    {
	$statusFlags = $this->listAll()[0];
	return $statusFlags['max_caredays_for_children_under_age_1'];
    }

    public function getMaxWeeklyCareSitsForChildrenOverOne()
    {
	$statusFlags = $this->listAll()[0];
	return $statusFlags['max_caredays_for_children_over_age_1'];
    }

    public function getMaxCareHoursPerWeek()
    {
	$statusFlags = $this->listAll()[0];
	return $statusFlags['max_carehours_per_week'];
    }

}